﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace WomanMotion.WebApi.Infrastructure.Common
{
    /// <summary>
    /// 字符串加密解密
    /// </summary>
    public static class StringEncryptionAndDecryption
    {
        /// <summary>
        /// 字符串Sha256加密
        /// </summary>
        /// <param name="input">需要加密的字符串</param>
        /// <returns>加密好的字符串</returns>
        public static string Sha256(this string input)
        {
            if (String.IsNullOrEmpty(input)) return string.Empty;
            using (var sha = SHA256.Create())
            {
                var bytes = Encoding.UTF8.GetBytes(input);
                var hash = sha.ComputeHash(bytes);
                return Convert.ToBase64String(hash);
            }
        }
        /// <summary>
        /// 字符串Sha512加密
        /// </summary>
        /// <param name="input">需要加密的字符串</param>
        /// <returns>加密好的字符串</returns>
        public static string Sha512(this string input)
        {
            if (string.IsNullOrEmpty(input)) return string.Empty;
            using (var sha = SHA512.Create())
            {
                var bytes = Encoding.UTF8.GetBytes(input);
                var hash = sha.ComputeHash(bytes);
                return Convert.ToBase64String(hash);
            }
        }
    }
}
